<template>
  <!--  :default-active="menus[0].path" -->
  <el-menu :default-active="menus[0].path"
           class="main-menu-vertical"
           @open="handleOpen"
           @close="handleClose"
           background-color="#545C65"
           text-color="#fff"
           active-text-color="#E3D80C"
           style="border-right:0px"
  >
    <div class="logo">
      <img src="@/assets/logo.png">
    </div>
    <h3 class="logo-title">果蔬检测与定位</h3>
    <h5 class="logo-sub-title">Web端</h5>
    <!-- 没有子菜单的   -->
    <el-menu-item  @click="clickMenu(item)" :index="item.path" v-for="item in noChildrenMenu" :key="item.path">
      <i :class="item.icon"></i>
      <span slot="title">{{item.label}}</span>
    </el-menu-item>
    <!-- 有子菜单的   -->
    <el-submenu :index="item.label" v-for="item in hasChildrenMenu" :key="item.label">
      <template slot="title">
        <i :class="item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item @click="clickMenu(subItem)" :index="subItem.path" v-for="subItem in item.children" :key="subItem.path">
          {{ subItem.label }}
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>

  </el-menu>
</template>

<script>
import {mapState,mapMutations} from 'vuex'

export default {
  name: "CommonAside",
  data() {
    return {
      // isCollapse: false,
      menus: [
        {
          path: '/home',
          name: 'Home',
          label: '首页',
          icon: 'el-icon-s-home',
          url: '/Home'
        },{
          path: '/detect',
          name: 'Detect',
          label: '检测与定位',
          icon: 'el-icon-camera-solid',
          url: '/Detect'
        },{
          path: '/history',
          name: 'History',
          label: '历史记录',
          icon: 'el-icon-s-claim',
          url: '/History'
        },{
          path: '/zone',
          name: 'Zone',
          label: '地块管理',
          icon: 'el-icon-s-shop',
          url: '/Zone'
        },{
          path: '/fruit',
          name: 'Fruit',
          label: '果蔬类型管理',
          icon: 'el-icon-s-shop',
          url: '/Fruit'
        },
      ]
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    clickMenu(item){
      this.$router.push({
        name: item.name
      })
     
    }

  },
  computed: {
    noChildrenMenu() {
      return this.menus.filter(item => !item.children);
    },
    hasChildrenMenu() {
      return this.menus.filter(item => item.children);
    }
  }
}
</script>

<style lang="less" scoped>
.main-menu-vertical{
  height: 100vh;
  width: 200px;
  .logo{
    height: 80px;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    img{
      height: 90%;
      width: auto;
      //margin: 0 auto;
    }
  }

  .logo-title{
    text-align: center;
    color: #D3DCE6;
    line-height: 60px;
  }

  .logo-sub-title{
    text-align: center;
    color: #D3DCE6;
    line-height: 36px;
  }
}
.main-menu-vertical:not(.el-menu--collapse) {
  width: 200px;
  /*min-height: 400px;*/
  height: 100vh;
}

.el-menu{
  height: 100vh;
  margin: 0;
}
</style>